package com.icedevcloud.auth.controller;

import com.icedevcloud.auth.controller.dto.LoginReqDto;
import com.icedevcloud.auth.controller.dto.LoginResDto;
import com.icedevcloud.auth.service.IAuthService;
import com.icedevcloud.common.core.api.R;
import com.icedevcloud.common.core.log.IceLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 认证 前端控制器
 * </p>
 *
 * @author dengbing
 * @since 2023-08-12
 */
@Tag(name = "认证接口类")
@RequiredArgsConstructor
@RestController
public class AuthController {

    private final IAuthService iAuthService;

    @IceLog
    @Operation(summary = "登录接口")
    @PostMapping("/login")
    public R<LoginResDto> login(@RequestBody @Validated LoginReqDto loginReqDto) {
        LoginResDto resDto = iAuthService.login(loginReqDto);
        return R.ok(resDto);
    }

    @IceLog
    @Operation(summary = "退出登录接口")
    @PostMapping("/logout")
    public R<LoginResDto> logout() {
        iAuthService.logout();
        return R.ok(null);
    }

}
